package com.bysj.controller;

import com.bysj.entity.CollectedGoods;
import com.bysj.entity.News;
import com.bysj.service.CollectedGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("collectgoods")
public class CollectedGoodsController {
    @Autowired
    CollectedGoodsService collectedGoodsService;
    //添加被收藏的商品
    @ResponseBody
    @RequestMapping("/addCollectGoods")
    public String addCollectGoods(@RequestBody CollectedGoods collectedGoods){
        collectedGoodsService.addCollectGoods(collectedGoods);
        return "success";
    }

    //获取用户所有的收藏商品
    @RequestMapping("getAllCollectGoods")
    public List<CollectedGoods> getAllCollectGoods(Integer id){
        return collectedGoodsService.getAllCollectGoods(id);
    }

    //根据用户和商品id删除已收藏的商品
    @ResponseBody
    @RequestMapping("/deleteCollectGoodsById")
    public String deleteCollectGoodsById(Integer gid , Integer uid){
        collectedGoodsService.deleteCollectGoodsById(gid , uid);
        return "success";
    }
}
